/*======================================================================
== Copyright : BlueCurve (c)
== Licence   : Gnu/GPL v2.x
== Author    : Teddy Albina
== Email     : bluecurveteam@gmail.com
== Web site  : http://www.codeplex.com/BlueCurve
========================================================================*/
using System;
using System.Net;


namespace RobotRules
{
	/// <summary>
	/// The base class for exceptions thrown when an error occurs that is related to Internet robots.
	/// </summary>
	public abstract class RobotException : ApplicationException
	{
		public RobotException() : base()
		{
		}

		public RobotException(string message) : base(message)
		{
		}

		public RobotException(string message, Exception inner) : base(message, inner)
		{
		}
	}


	/// <summary>
	/// The exception that is thrown when a robot control file has an inappropriate content type.
	/// </summary>
	public class ContentTypeException : RobotException
	{
		private const string DEFAULT_MESSAGE = "The content type is not valid.";


		private string _contentType = null;

		public string ContentType
		{
			get { return _contentType; }
			set { _contentType = value; }
		}


		public ContentTypeException(string contentType) : base(DEFAULT_MESSAGE)
		{
			_contentType = contentType;
		}

		public ContentTypeException(string contentType, Exception inner) : base(DEFAULT_MESSAGE, inner)
		{
			_contentType = contentType;
		}

		public ContentTypeException(string message, string contentType) : base(message)
		{
			_contentType = contentType;
		}

		public ContentTypeException(string message, string contentType, Exception inner)
			: base(message, inner)
		{
			_contentType = contentType;
		}
	}


	/// <summary>
	/// The exception that is thrown when a robot control file cannot be downloaded due to
	/// a transfer problem (not just an HTTP status code indicating failure).
	/// </summary>
	public class DownloadFailedException : RobotException
	{
		private const string DEFAULT_MESSAGE = "The download failed.";


		private Uri _address = null;

		public Uri Address
		{
			get { return _address; }
		}


		public override string Message
		{
			get { return base.Message + Environment.NewLine + _address; }
		}


		public DownloadFailedException() : base(DEFAULT_MESSAGE)
		{
		}

		public DownloadFailedException(Uri address) : base(DEFAULT_MESSAGE)
		{
			_address = address;
		}

		public DownloadFailedException(Uri address, Exception inner) : base(DEFAULT_MESSAGE)
		{
			_address = address;
		}

		public DownloadFailedException(string message, Uri address) : base(message)
		{
			_address = address;
		}

		public DownloadFailedException(string message, Uri address, Exception inner) : base(message, inner)
		{
			_address = address;
		}
	}


	/// <summary>
	/// The exception that is thrown when an invalid user agent token is specified.
	/// </summary>
	public class InvalidUserAgentException : RobotException
	{
		private const string DEFAULT_MESSAGE = "The user agent token is invalid.";


		private string _userAgent = null;

		public string UserAgent
		{
			get { return _userAgent; }
			set { _userAgent = value; }
		}


		public override string Message
		{
			get { return base.Message + Environment.NewLine + _userAgent; }
		}


		public InvalidUserAgentException(string userAgent) : base(DEFAULT_MESSAGE)
		{
			_userAgent = userAgent;
		}

		public InvalidUserAgentException(string userAgent, Exception inner) : base(DEFAULT_MESSAGE, inner)
		{
			_userAgent = userAgent;
		}

		public InvalidUserAgentException(string message, string userAgent) : base(message)
		{
			_userAgent = userAgent;
		}

		public InvalidUserAgentException(string message, string userAgent, Exception inner)
			: base(message, inner)
		{
			_userAgent = userAgent;
		}
	}


	/// <summary>
	/// The exception that is thrown when the specified URI does not match the site to which
	/// the robot control file referred.
	/// </summary>
	public class SiteMismatchException : RobotException
	{
		private const string DEFAULT_MESSAGE =
			"The parser cannot evaluate the URI because it is part of a different site.";


		public SiteMismatchException() : base(DEFAULT_MESSAGE)
		{
		}

		public SiteMismatchException(string message) : base(message)
		{
		}

		public SiteMismatchException(string message, Exception inner) : base(message, inner)
		{
		}
	}
}
